package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.furnace.FurnaceIdData;
import com.jinmdz.fmis.api.admin.model.furnace.FurnaceListData;
import com.jinmdz.fmis.api.admin.model.furnace.FurnaceLoadData;
import com.jinmdz.fmis.api.admin.model.furnace.FurnaceSaveData;
import com.jinmdz.fmis.api.admin.service.FurnaceService;
import com.jinmdz.fmis.api.api.model.common.IdVersionData;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 火化炉维护信息相关接口
 *
 * @author LiCongLu
 * @date 2020-03-10 16:54
 */
@Api(description = "火化炉维护信息相关接口")
@RestController()
@RequestMapping("/admin/furnace")
public class FurnaceController extends BaseController {

    @Resource
    private FurnaceService furnaceService;

    /**
     * 加载火化炉信息
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-03-10 16:11
     */
    @ApiOperation(value = "加载火化炉信息", notes = "加载火化炉分类【cremation_furnace】表中所有有效火化炉信息")
    @PostMapping("/load-furnace-list")
    public BaseResult<ArrayList<FurnaceListData>> loadFurnaceList() {
        return resultHandler(userItem -> furnaceService.loadFurnaceList());
    }

    /**
     * 加载火化炉信息
     *
     * @param data 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-10 16:53
     */
    @ApiOperation(value = "根据【cremation_furnace】表中id加载火化炉信息", notes = "根据ID加载火化炉信息")
    @PostMapping("/load-furnace-with-id")
    public BaseResult<FurnaceLoadData>  loadFurnaceWithId(@RequestBody FurnaceIdData data) {
        return resultHandler(data, userItem -> furnaceService.loadFurnaceWithId(data));
    }

    /**
     * 保存火化炉信息到cremation_furnace表中
     *
     * @param data 火化炉请求数据
     * @return
     * @author LiCongLu
     * @date 2020-03-10 16:54
     */
    @ApiOperation(value = "保存火化炉信息到【cremation_furnace】表中", notes = "保存火化炉信息到【cremation_furnace】表中")
    @PostMapping("/save-furnace")
    public BaseResult saveFurnace(@RequestBody FurnaceSaveData data) {
        return resultHandler(data, userItem -> furnaceService.saveFurnace(userItem, data));
    }

    /**
     * 从cremation_furnace表中删除指定id的火化炉信息记录
     *
     * @param data 主键和版本号
     * @return
     * @author LiCongLu
     * @date 2020-03-10 10:52
     */
    @ApiOperation(value = "从cremation_furnace表中删除指定id的火化炉信息记录", notes = "从cremation_furnace表中删除指定id的火化炉信息")
    @PostMapping("/delete-furnace-with-id")
    public BaseResult deleteFurnaceWithId(@RequestBody ArrayList<IdVersionData> data) {
        return resultHandler(data, userItem -> furnaceService.deleteFurnaceWithId(userItem, data));
    }
}
